#include <vector>
#ifndef MODELS_TIME_POINT_H

#include <string>

#include <nlohmann/json.hpp>

namespace models {

struct TimePoint {
  int t;
  std::string pid;
  std::string step;
  std::string action;

  // 序列化方法
  nlohmann::json to_json() const {
    return nlohmann::json{
        {"t", t}, {"pid", pid}, {"step", step}, {"action", action}};
  }

  // 反序列化方法
  static TimePoint from_json(const nlohmann::json &j) {
    TimePoint tp;
    j.at("t").get_to(tp.t);
    j.at("pid").get_to(tp.pid);
    j.at("step").get_to(tp.step);
    j.at("action").get_to(tp.action);
    return tp;
  }

  static nlohmann::json to_json_any(std::vector<TimePoint> const &tps) {
    nlohmann::json j;
    for (auto &tp : tps) {
      j.push_back(tp.to_json());
    }
    return j;
  }

  static std::vector<TimePoint> from_json_any(nlohmann::json const &j) {
    std::vector<TimePoint> tps;
    for (auto &tp : j) {
      tps.push_back(TimePoint::from_json(tp));
    }
    return tps;
  }
};

} // namespace models
#endif